<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="业主姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入业主姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择审核状态" clearable size="small">
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:communityUser:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:communityUser:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:communityUser:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
		  :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['system:communityUser:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="communityUserList" border size="mini" stripe @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键id" align="center" prop="id" v-if="false"/>
      <el-table-column label="业主姓名" align="center" prop="name" />
      <el-table-column label="手机号" align="center" prop="phone" width="110"/>
      <el-table-column label="小区名称" align="center" prop="communityName" />
      <el-table-column label="单元名称" align="center" prop="unitName" />
      <el-table-column label="门牌号" align="center" prop="doorNum" />
      <el-table-column label="车牌号" align="center" prop="carLicenseNumber" />
      <el-table-column label="车位号" align="center" prop="parkingSpace" />
      <el-table-column label="卡数量" align="center" prop="cardNum" />
      <el-table-column label="门禁卡号" align="center" prop="cardNos" />
      <el-table-column label="人脸图片" align="center" prop="fpath" >
        <template  slot-scope="scope">
          <img :src="scope.row.fpath" :alt="scope.row.title" @click="showImg(scope.row.fpath)" width="20%" height="20%">
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="status" :formatter="statusFormat" />
      <el-table-column label="失败原因" align="center" prop="reason" >
        <template slot-scope="scope">
          <div v-if="scope.row.status == 0 && scope.row.reason" >
            <el-popover
              placement="top-start"
              width="300"
              trigger="hover"
              :disabled="scope.row.reason.length <= 5"
            >
              <div v-html="scope.row.reason"></div>
              <span slot="reference" v-if="scope.row.reason.length <= 5">{{scope.row.reason}}</span>
              <span slot="reference" v-if="scope.row.reason.length > 5">{{scope.row.reason.substr(0, 5) + "..."}}</span>
            </el-popover>
          </div>
          <span v-else></span>
        </template>
      </el-table-column>
      <el-table-column label="月物业费" align="center" prop="monthFee" >
        <template slot-scope="scope">
          <span>{{scope.row.monthFee / 100}}</span>
        </template>
      </el-table-column>
      <el-table-column label="物业费到期时间" align="center" prop="endtime" width="120">
        <template slot-scope="scope">
          <span v-if="scope.row.endtime ==null || scope.row.endtime == '' " style="color: red">未交物业费</span>
          <span v-if="scope.row.feeStatus ==0 " style="color: red">{{ parseTime(scope.row.endtime, '{y}-{m}-{d}') }}</span>
          <span v-else-if="scope.row.feeStatus ==1 " style="color: green">{{ parseTime(scope.row.endtime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="用户类型" align="center" prop="type" :formatter="typeFormat" />-->
      <el-table-column label="操作" align="center" fixed="right" width="350px" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.fpath && scope.row.status == 2 "
            size="mini"
            type="text"
            icon="el-icon-bell"
            @click="handleUpdateFace(scope.row)"
            v-hasPermi="['system:communityUser:updateFace']"
          >更新人脸</el-button>
          <el-button
            v-if="scope.row.status != 2"
            size="mini"
            type="text"
            icon="el-icon-bell"
            @click="handleReview(scope.row)"
            v-hasPermi="['system:communityUser:review']"
          >审核</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:communityUser:edit']"
          >修改</el-button>
          <el-button
            v-if="scope.row.status == 2 "
            size="mini"
            type="text"
            icon="el-icon-circle-plus-outline"
            @click="handleAddCard(scope.row)"
            v-hasPermi="['system:communityUser:addCardNum']"
          >添加卡</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:communityUser:remove']"
          >删除</el-button>
          <el-button
            v-if=" scope.row.status == 2 "
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handlePayFee(scope.row)"
            v-hasPermi="['system:communityMonthFee:add']"
          >缴物业费</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!--  查看图  -->
    <el-dialog :title="imgTitle" :visible.sync="imgOpen" v-if="imgOpen" width="50%" append-to-body>
      <show-imgs :imgs="imgUrl"></show-imgs>
    </el-dialog>
    <!-- 审核业主 -->
    <el-dialog :title="title" :visible.sync="openReview" width="40%" append-to-body>
      <el-form ref="form" :model="form" :rules="rulesReview"  label-width="120px">
        <el-form-item label="审核状态" prop="status">
          <el-select v-model="form.status" placeholder="请选择审核状态" style="width: 100%">
            <el-option
              v-for="dict in statusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审核说明" prop="reason">
          <el-input v-model="form.reason" placeholder="请输入审核说明" />
        </el-form-item>
        <el-form-item label="所属小区" prop="communityId">
          <el-select v-model="form.communityId"
                     :disabled="isReview"
                     placeholder="请选择所属小区"
                     filterable clearable size="small"
                     @change="getUnitListByCommunityId(form.communityId)"
                     style="width: 100%">
            <el-option
              v-for="community in communityOptions"
              :key="community.id"
              :label="community.name"
              :value="Number(community.id)"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="所属单元" prop="unitId">
          <el-select v-model="form.unitId" :disabled="isReview"  style="width: 100%"  placeholder="请选择单元名称" filterable clearable size="small" >
            <el-option
              v-for="unit in unitOptions"
              :key="unit.id"
              :label="unit.unitName"
              :value="Number(unit.id)"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="业主姓名" prop="name">
          <el-input v-model="form.name" :disabled="isReview"  placeholder="请输入业主姓名" />
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input v-model="form.phone" :disabled="isReview"  placeholder="请输入手机号" />
        </el-form-item>
        <el-form-item label="门牌号" prop="doorNum">
          <el-input v-model="form.doorNum" :disabled="isReview" placeholder="请输入门牌号" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitReviewForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 缴物业费 -->
    <el-dialog :title="title" :visible.sync="openPayFee" width="40%" append-to-body>
      <el-form ref="formPayFee" :model="formPayFee" :rules="rulesPay"  label-width="120px">
        <el-form-item label="所属小区" prop="communityId">
          <el-select v-model="formPayFee.communityId"
                     disabled
                     placeholder="请选择所属小区"
                     filterable clearable size="small"
                     @change="getUnitListByCommunityId(formPayFee.communityId)"
                     style="width: 100%">
            <el-option
              v-for="community in communityOptions"
              :key="community.id"
              :label="community.name"
              :value="Number(community.id)"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="所属单元" prop="unitId">
          <el-select v-model="formPayFee.unitId" disabled  style="width: 100%"  placeholder="请选择单元名称" filterable clearable size="small" >
            <el-option
              v-for="unit in unitOptions"
              :key="unit.id"
              :label="unit.unitName"
              :value="Number(unit.id)"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="业主姓名" prop="name">
          <el-input v-model="formPayFee.name" disabled  placeholder="请输入业主姓名" />
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input v-model="formPayFee.phone" disabled  placeholder="请输入手机号" />
        </el-form-item>
        <el-form-item label="门牌号" prop="doorNum">
          <el-input v-model="formPayFee.doorNum" disabled placeholder="请输入门牌号" />
        </el-form-item>
        <el-form-item label="月物业费" prop="monthFee">
          <el-input v-model="formPayFee.monthFee" disabled placeholder="请输入月物业费" />
        </el-form-item>
        <el-form-item label="物业费到期时间" prop="endtime">
          <el-date-picker clearable size="small" disabled
                          style="width: 100%"
                          v-model="formPayFee.endtime"
                          type="datetime"
                          value-format="yyyy-MM-dd HH:mm:ss"
                          placeholder="选择物业费到期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="缴纳费用" prop="payPrice">
          <el-input-number v-model="formPayFee.payPrice"
                           :min="formPayFee.monthFee"
                           :step="formPayFee.monthFee"
                           placeholder="请输入缴纳费用" style="width: 100%"/>
        </el-form-item>
        <el-form-item label="选择到期时间" prop="validityPeriod">
          <el-date-picker clearable size="small"
                          style="width: 100%"
                          v-model="formPayFee.validityPeriod"
                          type="datetime"
                          value-format="yyyy-MM-dd HH:mm:ss"
                          placeholder="选择到期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="formPayFee.remark"  placeholder="请输入缴费备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitPayFeeForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加卡 -->
    <el-dialog :title="title" :visible.sync="openAddCard" width="40%" append-to-body>
      <el-form ref="form" :model="form"   label-width="120px">
        <el-form-item label="添加卡" prop="cardNos">
          <el-input v-model="form.cardNos" placeholder="添加卡，多张卡用英文逗号隔开" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitAddCardForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改业主信息管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="40%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules"   label-width="120px">
        <el-form-item label="所属小区" prop="communityId">
          <el-select v-model="form.communityId"
                     placeholder="请选择所属小区" filterable clearable
                     size="small" @change="getUnitListByCommunityId(form.communityId)"
                     style="width: 100%" >
            <el-option
              v-for="community in communityOptions"
              :key="community.id"
              :label="community.name"
              :value="Number(community.id)"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="所属单元" prop="unitId">
          <el-select v-model="form.unitId"  style="width: 100%"   placeholder="请选择单元名称" filterable clearable size="small" >
            <el-option
              v-for="unit in unitOptions"
              :key="unit.id"
              :label="unit.unitName"
              :value="Number(unit.id)"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="业主姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入业主姓名" />
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入手机号" />
        </el-form-item>
        <el-form-item label="车牌号" prop="carLicenseNumber">
          <el-input v-model="form.carLicenseNumber" placeholder="请输入车牌号" />
        </el-form-item>
        <el-form-item label="人脸图片" prop="fpath">
          <upload-img v-model="form.fpath" :limit="1"></upload-img>
        </el-form-item>
        <el-form-item label="停车位编号" prop="parkingSpace">
          <el-input v-model="form.parkingSpace" placeholder="请输入停车位" />
        </el-form-item>
        <el-form-item label="门牌号" prop="doorNum">
          <el-input v-model="form.doorNum" placeholder="请输入门牌号" />
        </el-form-item>
        <el-form-item label="月物业费" prop="monthFee">
          <el-input v-model="form.monthFee" placeholder="请输入月物业费" />
        </el-form-item>
        <el-form-item label="用户类型" prop="type">
          <el-select v-model="form.type" placeholder="请选择用户类型"  style="width: 100%" >
            <el-option
              v-for="dict in typeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCommunityUser, getCommunityUser, delCommunityUser, addCommunityUser,
  updateCommunityUser, exportCommunityUser,reviewCommunityUser,updateFace,addCardNum } from "@/api/system/communityUser";
import {addCommunityMonthFee} from "@/api/system/communityMonthFee";
import {getAllList} from "@/api/system/community";
import {getListByCommunity} from "@/api/system/communityUnit";
import UploadImg from "@/components/UploadImg";
import ShowImgs from "@/components/ShowImgs";
export default {
  name: "CommunityUser",
  components: {
    ShowImgs,
    UploadImg
  },
  data() {
    return {
	  //按钮loading
	  buttonLoading: false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      //是否是审核
      isReview: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 业主信息管理表格数据
      communityUserList: [],
      // 弹出层标题
      title: "",
      imgOpen: false,
      imgTitle: "",
      imgUrl: "",
      // 是否显示弹出层
      open: false,
      //添加卡弹出层
      openAddCard: false,
      //缴物业费
      openPayFee: false,
      //审核弹出层
      openReview: false,
      // 审核状态：0审核失败 1审核中  2审核通过字典
      statusOptions: [],
      //小区下拉列表
      communityOptions: [],
      //小区单元下拉列表
      unitOptions: [],
      // 物业费缴纳状态：0未缴纳 1已缴纳字典
      feeStatusOptions: [],
      // 用户类型:0业主，1，租客字典
      typeOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        communityId: undefined,
        name: undefined,
        phone: undefined,
        status: undefined,
      },
      // 表单参数
      form: {},
      // 表单参数
      formPayFee: {},
      // 表单校验
      rules: {
        communityId: [
          { required: true, message: "请选择所属小区", trigger: "change" }
        ],
        unitId: [
          { required: true, message: "请选择所属小区单元", trigger: "change" }
        ],
        name: [
          { required: true, message: "业主姓名不能为空", trigger: "change" }
        ],
        phone: [
          { required: true, message: "业主电话不能为空", trigger: "change" ,pattern: /^1[3456789]\d{9}$/}
        ],
        doorNum: [
          { required: true, message: "业主门牌号不能为空", trigger: "change" }
        ],
        monthFee: [
          {  message: "物业费大于0", trigger: "change" ,pattern: /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/}
        ],

      },
      rulesReview: {
      },
      rulesPay: {
        payPrice: [
          { required: true, message: "请输入缴纳费用", trigger: "blur" }
        ],
        validityPeriod: [
          { required: true, message: "选择物业到期时间", trigger: "blur" }
        ],
      },
    };
  },
  created() {
    this.getList();
    this.getCommunityList();
    this.getDicts("community_user_status").then(response => {
      this.statusOptions = response.data;
    });
    this.getDicts("community_user_fee_status").then(response => {
      this.feeStatusOptions = response.data;
    });
    this.getDicts("community_user_type").then(response => {
      this.typeOptions = response.data;
    });
  },
  methods: {
    /** 查询业主信息管理列表 */
    getList() {
      this.loading = true;
      listCommunityUser(this.queryParams).then(response => {
        this.communityUserList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //获取小区列表
    getCommunityList(){
      let data={};
      getAllList(data).then(response => {
        this.communityOptions = response.data
      });
    },
    //图片详情
    showImg(imgUrl) {
      this.imgOpen = true;
      this.imgTitle = "图片详情";
      this.imgUrl = imgUrl;
    },
    //获取小区单元列表
    getUnitListByCommunityId(communityId){
      this.unitOptions = [];
      this.queryParams.unitId = undefined;
      this.form.unitId = undefined;
      let data={
        communityId:communityId
      };
      getListByCommunity(data).then(response => {
        this.unitOptions = response.data
      });
    },
    // 审核状态：0审核失败 1审核中  2审核通过字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 物业费缴纳状态：0未缴纳 1已缴纳字典翻译
    feeStatusFormat(row, column) {
      return this.selectDictLabel(this.feeStatusOptions, row.feeStatus);
    },
    // 用户类型:0业主，1，租客字典翻译
    typeFormat(row, column) {
      return this.selectDictLabel(this.typeOptions, row.type);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openReview = false;
      this.isReview = false;
      this.openAddCard = false;
      this.openPayFee = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        userId: undefined,
        communityId: undefined,
        unitId: undefined,
        name: undefined,
        phone: undefined,
        carLicenseNumber: undefined,
        faceStatus: 0,
        faceId: undefined,
        faceFeature: undefined,
        cardNum: undefined,
        cardNos: undefined,
        base64: undefined,
        fpath: undefined,
        parkingSpace: undefined,
        doorNum: undefined,
        status: undefined,
        reason: undefined,
        monthFee: undefined,
        feeStatus: undefined,
        endtime: undefined,
        updatetime: undefined,
        type: undefined,
        createtime: undefined
      };
      this.resetForm("form");
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加业主信息管理";
    },
    /** 添加卡 */
    handleAddCard(row) {
      this.reset();
      this.loading = true;
      const id = row.id ;
      getCommunityUser(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.openAddCard = true;
        this.title = "添加卡，多张卡用英文逗号隔开";
      });
    },
    /** 缴物业费 */
    handlePayFee(row) {
      this.reset();
      this.loading = true;
      const id = row.id ;
      getCommunityUser(id).then(response => {
        this.loading = false;
        this.formPayFee = response.data;
        this.formPayFee.monthFee = this.formPayFee.monthFee / 100;
        this.openPayFee = true;
        this.title = "缴物业费";
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      getCommunityUser(id).then(response => {
        this.loading = false;
        this.getUnitListByCommunityId(response.data.communityId);
        this.form = response.data;
        this.form.monthFee = this.form.monthFee/100;
        this.open = true;
        this.title = "修改业主信息管理";
      });
    },
    /** 审核按钮操作 */
    handleReview(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      getCommunityUser(id).then(response => {
        this.loading = false;
        this.getUnitListByCommunityId(response.data.communityId);
        this.form = response.data;
        this.openReview = true;
        this.isReview = true;
        this.title = "业主审核";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.carLicenseNumber && this.isVehicleNumber(this.form.carLicenseNumber) == false){
              this.msgError("请填写正确的车牌号");
              return false;
          }
          this.form.monthFee = this.form.monthFee * 100;
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateCommunityUser(this.form).then(response => {
              this.buttonLoading = false;
              this.msgSuccess("修改成功");
              this.open = false;
              this.isReview = false;
              this.getList();
            });
          } else {
            addCommunityUser(this.form).then(response => {
              this.buttonLoading = false;
              this.msgSuccess("新增成功");
              this.open = false;
              this.isReview = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 审核提交按钮 */
    submitReviewForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          let reviewData={
            id:this.form.id,
            status:this.form.status,
            reason:this.form.reason,
          }
          if (reviewData.status == 1 ){
            this.msgError("审核状态不能为审核中!")
            return false;
          }
          this.buttonLoading = true;
          reviewCommunityUser(reviewData).then(response => {
            this.buttonLoading = false;
            this.msgSuccess("审核成功");
            this.isReview = false;
            this.openReview = false;
            this.getList();
          });
        }
      });
    },
    /** 添加卡 */
    submitAddCardForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          let addCardData={
            id:this.form.id,
            cardNos:this.form.cardNos,
          }
          this.buttonLoading = true;
          addCardNum(addCardData).then(response => {
            this.buttonLoading = false;
            this.msgSuccess("操作成功");
            this.openAddCard = false;
            this.getList();
          });
        }
      });
    },
    /** 缴纳物业费 */
    submitPayFeeForm() {
      this.$refs["formPayFee"].validate(valid => {
        if (valid) {

          if (this.formPayFee.payPrice < this.formPayFee.monthFee){
            this.msgError("请按最低物业费【"+this.formPayFee.monthFee+"元】录入，或在业主信息栏修改该业主月物业费价格");
            return false;
          }
          this.formPayFee.payPrice = this.formPayFee.payPrice * 100
          this.buttonLoading = true;
          addCommunityMonthFee(this.formPayFee).then(response => {
            this.buttonLoading = false;
            this.msgSuccess("物业费缴纳成功");
            this.openPayFee = false;
            this.getList();
          });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除业主信息管理编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.loading = true;
          return delCommunityUser(ids);
        }).then(() => {
          this.loading = false;
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 更新人脸按钮操作 */
    handleUpdateFace(row) {
      this.$confirm('确定更新名称为"' + row.name + '"的业主人脸吗?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.loading = true;
          return updateFace(row.id);
        }).then(() => {
          this.loading = false;
          this.getList();
          this.msgSuccess(row.name+"人脸更新成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有业主信息管理数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportCommunityUser(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
